#include<stdio.h>
#define MAXSIZE 100
typedef int elemtype;
typedef struct{
    elemtype data[MAXSIZE];
     int length;
}SeqList;

void initList(SeqList*L)
{
    L->length=0;    
}

int appendelem(SeqList*L,elemtype e)
{
    if(L->length>=MAXSIZE)
    {
        printf("顺序表已满");
    }
    L->data[L->length]=e;
    L->length++;
    return 1;
}

int findlist(SeqList*L,elemtype e)
{
    for(int i=0;i<L->length;i++)
    {
        if(L->data[i]==e)
        {
            return i+1;
        }
    }
    return 0;
}
void Listelem(SeqList*L)
{
    for(int i=0;i<L->length;i++)
    {
    printf("%d\t",L->data[i]);
    }
    printf("\n");
}

int insertelem(SeqList*L,elemtype a,int post)
{
    if(post<=L->length)
    {
        for(int i=L->length-1;i>=post-1;i--)
        {
        L->data[i+1]=L->data[i];
        }
    }
    L->data[post-1]=a;
    L->length++;
    return 1;
}
int deleteelem(SeqList*L,int post,elemtype*e)
{
    *e=L->data[post-1];
    if(post<L->length)
    {
        for(int i=post;i<L->length;i++)
        {
            L->data[i-1]=L->data[i];
        }
    }
    L->length--;
    return 1;
}
int main()
{
    SeqList list;
    initList(&list);
    printf("初始化成功，目前长度占用%d\n",list.length);
    printf("目前占用内存%zu字节\n",sizeof(list.data));
    appendelem(&list,12);
    appendelem(&list,16);
    appendelem(&list,15);
    appendelem(&list,1);
    Listelem(&list);
    insertelem(&list,28,2);
    Listelem(&list);
    elemtype deldata;
    deleteelem(&list,1,&deldata);
    Listelem(&list);
    printf("%d\n", findlist(&list,15)); 
    return 0;
}


